//
//	Return the address of the max value in the array
//
//	Test Notes:
//	I stuck with the generic C design of this function.
//	In C99 this can be done much easier with new array management
//
//	compile with gcc test4.cpp -Wall -o test4.exe
//
#include <stdio.h>

int* ReturnMaxAddrFromArray(int *array, int arrayCt)
{
	int* retVal = array;						// declare retVal and init
	int	 testVal = array[0];					// init a local comparison value

	for (int idx=0; idx<arrayCt; idx++) {		//	loop through array
		if (array[idx] > testVal) {				//	test for the largest value
			testVal = array[idx];				//	save the larger value
			retVal = &array[idx];				//	if larger, store the address
		}
		printf("idx: %d array: %d testVal: %d\n", idx, array[idx], testVal);
	}

	return retVal;
}

int main(void)
{
	int  test_arr[] = {1,3,4,7,2,-3};
	int	 test_arr_ct = sizeof(test_arr)/sizeof(int);
	int* a1;

	a1 = ReturnMaxAddrFromArray(test_arr, test_arr_ct);
	printf("answer: 0x%08lx ",(unsigned long)a1);
	printf("value: %d\n",*a1);
}
